<taglib name="Admin\TagLib\EasyUI" />

<easyui:datagrid options="datagrid.options" fields="datagrid.fields" />

<div id="user-loginlog-datagrid-toolbar" style="padding:5px;height:auto">
     <form  id='loginlog-form' style="border-bottom:1px solid #ddd;margin-bottom:1px;padding:5px">
		<select name="search[fill_type]"  style="width:100px;padding:2px;margin-right:20px;" >
				<option value="tel">站点编号</option>
				<option value="wifi">智能WiFi ID</option>
		</select>
		：<input id='tel' class="easyui-validatebox"  type='text' name='search[fill_value]'  style="width:80px;margin-right:10px;" value="<{$mobile}>"/>
		开始日期：<input class="easyui-datebox" id="login_startdate" data-options="required:true"  name="search[start_date]" style="width: 128px;" value="<{$start_date}>" onchange="userLoginlogModule.changelinke()">
		结束日期：<input class="easyui-datebox" id="login_enddate" data-options="required:true"  name="search[end_date]" style="width: 128px;" value="<{$end_date}>">&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:void(0);" onclick="userLoginlogModule.search(this);" class="easyui-linkbutton" iconCls="icons-table-table">查询</a><br/><br/>
        
    	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icons-table-table_refresh'" onclick="userLoginlogModule.refresh()">刷新</a>&nbsp;
    	<a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icons-table-table_go'" onclick="userLoginlogModule.go(this)">导出Excel</a>
    </form>
	<br/>
	<div>
		&nbsp;共计：<span id='total'><{$total}></span>条 &nbsp;&nbsp;&nbsp;总共登录次数：<span id='ci'><{$total}></span>次&nbsp;&nbsp;登录WiFi设备：<span id='tai'><{$tai}></span>台  
	</div>
	<br/>
</div>

<script type="text/javascript">
$(function(){
	//var p = $("#user_loginlog_datagrid").datagrid('getPager');
	//$(p).pagination({pageSize:10});
	//$(this.datagrid).datagrid({pageNumber: 1, pageSize:100});
	 //$('#user_loginlog_datagrid').datagrid({pageNumber: 1, pageSize:100});
});
var userLoginlogModule = {
	dialog:   '#globel-dialog-div',
	datagrid: '#user_loginlog_datagrid',
	
	changelinke: function(){
		
		var start_date = $("input[name='search[start_date]']").val();
		console.log(start_date);	
		
	},
	//状态格式化
	status: function(key){
		var status = {'Not': '<font color="red">注册未激活</font>', 'Active': '已激活', 'Sell': '交易用户', 'Cancel': '注销'};
		return status[key] || '-';
	},
	//时间格式化
	time: function(val){
		return val != '1970-01-01 08:00:00' ? val : '';
	},
	
	//操作格式化
	operate: function(val, arr, index){
		var type = $('#type').val();
		var mobile= $("#tel").val();		
		var btn = [];
		if(type == 'tel'){
			if(mobile == ''){
				btn.push(' - ');
				return btn.join(' | ');
			}else{
				btn.push('<a href="javascript:void(0);" onclick="userLoginlogModule.toUseLoginDetail('+index+','+arr['mobile']+',\''+arr['ip_address']+'\',\''+arr.wifi_id+'\')">查看详情</a>');
				return btn.join(' | ');
			}			
		}else{
			
			btn.push(' - ');
			return btn.join(' | ');
		}		
	},
	
	count: function(val, arr, index){
		
		var btn = [];
		if(arr.count == undefined || arr.count == 1){
			btn.push(1);
			return btn.join(' | ');
		}else{
			btn.push("<span style='color:red;'>"+arr.count+"</span>");
			return btn.join(' | ');
		}
		
	},
	
	//页面跳转到登录明细页面
	toUseLoginDetail: function(index,mobile,ip_address,wifi_id){
		$('#user_loginlog_datagrid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#user_loginlog_datagrid').datagrid('getSelected');

		if (row){
			
			var queryParams = $(this.datagrid).datagrid('options').queryParams;
	        $.each($('#form').serializeArray(), function() {
	            queryParams[this['name']] = this['value'];
	        });
	        var start_date = $('#login_startdate').datetimebox('getValue');
	        var end_date = $('#login_enddate').datetimebox('getValue');
	        var type = $('#type').val();
	        
			href = '<{:U('admin/user/loginLogDetail')}>';
	    	href += '?mobile='+mobile;
	    	href += '&ip_address='+ip_address;
	    	href += '&wifi_id='+wifi_id;
	    	href +="&start_date="+start_date;
	    	href +="&end_date="+end_date;
	    	href +="&type="+type;
	    	baseModule.openUrl(href,"登录明细页面");
	    }
		return false;
		
	},
	
	//刷新
	refresh: function(){
		$(this.datagrid).datagrid('reload');
	},
    //查询
    search: function(that){
        var queryParams = $(this.datagrid).datagrid('options').queryParams;
        $.each($(that).parent('form').serializeArray(), function() {
            queryParams[this['name']] = this['value'];
        });
//         if(queryParams['search[start_date]']=='' && queryParams['search[end_date]']==''){
//         	$.app.method.tip('提示信息', '开始日期和结束日期 不能全部为空', 'error');
//         	return false;
//         };
       $(this.datagrid).datagrid({pageNumber: 1});
        
        var start_date = $('#login_startdate').datetimebox('getValue');
        var end_date = $('#login_enddate').datetimebox('getValue');
        
        var isValid = $('#user-loginlog-datagrid-toolbar').form('validate');
        
		if (!isValid){
			
			$.app.method.tip('提示信息', '开始日期或结束日期 不能为空', 'error');
			return false;
		} 
		
        $.post("/admin/user/loginLog?dosubmit=1",queryParams,function(msg){
        	$('#total').html(msg.total);
        	$('#ci').html(msg.ci);
        	$("#tai").html(msg.tai);
        });
    },
	//导出数据
	go: function(that){
		var queryParams = $(this.datagrid).datagrid('options').queryParams;
        $.each($(that).parent('form').serializeArray(), function(){
            queryParams[this['name']] = this['value'];
        });
        
        $(this.datagrid).datagrid({pageNumber: 1});
        var href="/admin/user/outExcel?mobile="+queryParams['search[mobile]']+"&start_date="+queryParams['search[start_date]']+"&end_date="+queryParams['search[end_date]'];
        window.location.href=href;
// 		$.post("/admin/user/outExcel",queryParams,function(msg){
			
//         });
	},
	
};
</script>